<?php
class admin_userModel extends baseModel{
    protected $table = 'admin_user';

    //管理组列表
    public function user_list($user=null) {
         $sql="
            SELECT A.*,B.name as gname
            FROM {$this->model->pre}admin_user A 
            LEFT JOIN {$this->model->pre}admin_group B ON A.gid = B.gid
            WHERE B.level>={$user['level']} 
            ORDER BY A.uid DESC
            ";
        return $this->model->query($sql);
    }

    //检测重复用户
    public function user_count($user,$id=null)
    {
        if(!empty($id)){
            $where=' AND id<>'.$id;
        }
        return $this->count('username="'.$user.'"'.$where); 
    }

    //管理组信息
    public function info($uid) {
        return $this->find('uid='.$uid);
    }

    //获取指定管理组列表
    public function content_list($uid) {
        return $this->select('uid in('.$uid.')','','uid desc');
    }

    //添加管理组
    public function add($data)
    {
        $data['regtime']=time();
        $data['logintime']=time();
        return $this->insert($data);
    }
    //编辑管理组
    public function edit($data)
    {
        $condition['uid']=intval($data['uid']);
        return $this->update($condition,$data); 
        
    }
    //删除管理组
    public function del($uid)
    {
        //删除关联
        return $this->delete('uid='.intval($uid)); 
    }

	
}